var isLogin = 0

// const baseUrl="http://localhost/" //正式地址
const baseUrl = 'https://community.chuangxiangdianli.com/api/' //正式地址
// const token = 'Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwOlwvXC93d3cuY2h1YW5neGlhbmcudGVzdFwvYXBpXC93ZWNoYXRcL2dldFVzZXJJbmZvQnlDb2RlXC8wMTNEVm0wdzMzRTVXVjIySWwydzNDblh2QjBEVm0wYyIsImlhdCI6MTYxNDgzOTc1NSwiZXhwIjoxNjE1NDQ0NTU1LCJuYmYiOjE2MTQ4Mzk3NTUsImp0aSI6IkJyTzJFNkdMRlRrRnQyY24iLCJzdWIiOjI0LCJwcnYiOiIyM2JkNWM4OTQ5ZjYwMGFkYjM5ZTcwMWM0MDA4NzJkYjdhNTk3NmY3In0.Ebm77XPmydjxR5p28PbK345IbPliKnS-jPsIexjHlGM'
// let token =
// 	'Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwczpcL1wvY29tbXVuaXR5LmNodWFuZ3hpYW5nZGlhbmxpLmNvbVwvYXBpXC93ZWNoYXRcL2dldFVzZXJJbmZvQnlDb2RlXC8wMTM4UDdHYTE1QXRJQTBrZmtGYTFGRDJBNDA4UDdHUSIsImlhdCI6MTYxNjE0MDIyNCwiZXhwIjoxNjE2NzQ1MDI0LCJuYmYiOjE2MTYxNDAyMjQsImp0aSI6IkF1dGlVekxsRzVnejhNb20iLCJzdWIiOjY1LCJwcnYiOiIyM2JkNWM4OTQ5ZjYwMGFkYjM5ZTcwMWM0MDA4NzJkYjdhNTk3NmY3In0.rxQW_cOE1ftonfAm_zmOQlnmV7Wi27Md9l7KAgQT9kU'

function commrequest(obj) {
	obj.header = obj.header || {}
	if (!obj.header['content-type']) {
		obj.header['content-type'] = 'application/x-www-form-urlencoded'
	}
	obj.isloading = obj.isloading || true
	obj.header['Authorization'] = 'Bearer' + ' ' + uni.getStorageSync('userInfo').token
	// console.log(obj.header['Authorization'])

	// obj.header["Authorization"]=token

	// obj.header["Authorization"]=token
	if (obj.isloading != 'none') {

		uni.showLoading({
			title: '加载中...'
		})
	}
	// url: baseUrl + obj.url,
	// data: obj.data,
	// header: obj.header,
	// method,
	uni.request({
		url: baseUrl + obj.url,
		header: obj.header,
		data: obj.data,
		method: obj.method,
		success: res => {
			uni.hideLoading()
			if (res.data.code != 200) {
				if (res.data.code == 20001) {
					obj.callBack(res)
					uni.navigateTo({
						url: '/login/registerinfo/index'
					})
				} else if (res.data.code == 401) {
					obj.callBack(res)
					uni.navigateTo({
						url: '/login/bindinguser/index'
					})
				} else if (res.data.code == 401) {
					obj.callBack(res)
					uni.navigateTo({
						url: '/login/bindinguser/index'
					})
				} else if (res.data.code == 500 && res.data.msg == '请先登录') {
					obj.callBack(res)
					uni.navigateTo({
						url: '/login/bindinguser/index'
					})
				} else if (res.data.appId) {
					// 微信支付前获取信息的接口
					obj.callBack(res)
				} else if (res.data.status) {
					obj.callBack(res)
				} else {
					uni.showToast({
						title: res.data.msg,
						icon: 'none'
					})
				}

				return
			}

			obj.callBack(res)
		},
		fail: res => {
			if (obj.isloading) {
				uni.hideLoading()
			}
			obj.fail(res.data)
			uni.showToast({
				title: '系统维护中，请稍后',
				icon: 'none'
			})
		},
		complete: () => {
			uni.hideLoading()
		}
	})
}

// ---------------------------------------    导出方法    ------------------------------------------
export default {
	commrequest,
	baseUrl
}
